<?php echo $this->Html->script(array('print'));?>
<?php app::import('model', 'Presentacionesmedicamento') ?>
<?php $presentacion = new Presentacionesmedicamento() ?>
<?php app::import('model', 'Medidasmedicamento')?>
<?php app::import('model', 'User') ?>
<?php $medida = new Medidasmedicamento();?>
<div id="content">
    <div class="grid_container">
        <div class="grid_12">
            <div class="widget_wrap">
                <div class="widget_top">
                    <span class="h_icon blocks_images"></span>
                    <h6>Receta</h6>
                </div>
                <div class="widget_content">
                    <div class="invoice_action_bar">
<!--                        <div class="btn_30_light">
                            <a href="#" title="Pay Now"><span class="icon zone_money_co"></span></a>
                        </div>-->
                        <div class="btn_30_light">
                            <a title="Print" id="btImprimir"><span class="icon printer_co"></span></a>
                        </div>
                        <div class="btn_30_light">
                            <a href="<?php echo $this->Html->url(array('controller'=>"Pacientes",'action' => 'verestadopaciente', $idConsultaExterna, 'receta')) ?>" title="Retornar"><span class="icon arrow_left_co"></span></a>
                        </div>
                    </div>
                    
                    <div id="zonaImpresion">
                        <!--<div style="width: 800px">-->
                            
                        
                        <table style="border: none">
                            <tr>
                                <td><?php echo $this->Html->image('hospital/hospitalLogo.png', array('width'=>250, 'height'=>60)) ?></td>                                        
                            </tr>
                        </table>
                       
                        <span class="clear"></span>
                        <hr>
                        
                        <?php //debug($receta)?>
                        <table style="font-size: 10px">
                            <tbody>
                                <tr>
                                    <td>
                                        <span style="font-size: 12px; padding-right: 5px">R/p</span> <b style="font-size: 12px; padding-right: 5px">
                                            <?php echo $receta[0]['Paciente']['ap_paterno'].' '.$receta[0]['Paciente']['ap_materno'].' '.$receta[0]['Paciente']['nombres']?>
                                        </b>
                                    </td>
                                    <td>
                                        <b>Edad <?php echo $receta[0]['Consultasexterna']['edad']?></b>
                                    </td>
                                </tr>
                                <?php $i=1; foreach($receta as $dato):?>
                                <tr>
                                    <td style="border-bottom: 1px solid; padding: 5px 10px 5px 5px;">
                                        <?php echo $i?>)&nbsp;
                                                   
                                        <?php if(!empty($dato['MedicamentosPaciente']['medicamento'])):?>
                                        <?php echo $dato['MedicamentosPaciente']['medicamento']?>
                                        
                                        <?php else:?>
                                        <?php $pm = $presentacion->find('first', array('conditions'=>array('Presentacionesmedicamento.id'=>$dato['Medicamento']['presentacionesmedicamento_id'])))?>
                                        <?php $med = $medida->find('first', array('conditions'=>array('Medidasmedicamento.id'=>$dato['Medicamento']['medidasmedicamento_id'])))?>
                                      
                                        <?php echo $dato['Medicamento']['nombre']; ?>&nbsp;
                                        <?php echo $dato['Medicamento']['porporcion'] ?>&nbsp;
                                        <?php echo $med['Medidasmedicamento']['sigla']?>&nbsp;en&nbsp;
                                        <?php echo $pm['Presentacionesmedicamento']['nombre']?>&nbsp;
                                        <?php echo $dmp['Medicamento']['porporcion']?>&nbsp;
                                        
                                        <?php endif;?>
                                        # &nbsp; <?php echo $dato['MedicamentosPaciente']['cantidad']; ?>
                                        <br/><?php echo $dato['MedicamentosPaciente']['dosis']; ?>                                        
                                    </td>
                                    <td style="border-bottom: 1px solid black; padding: 5px 10px 5px 5px;border-left: 1px solid black">
                                       <?php echo $i?>)&nbsp; <?php echo $dato['MedicamentosPaciente']['observaciones']; ?>
                                    </td>
                                </tr>
                                <?php $i++; endforeach;?>
                            </tbody>
                        </table>
                        <!--</div>-->
                        <!-- firma Dr -->
                        <?php $usuario = $this->Session->read('Auth.User') ?>
                            <div style="padding-top: 50px; " class="invoice_details">
                                <div style="text-align: left; font-size: 10px !important">
                                    <br/>
                                        Dr(a).<?php echo $usuario['nombre'] . ' ' . $usuario['apellido_paterno'] . ' ' . $usuario['apellido_materno'] ?>
                                        <br/>
                                        <span style="font-size: 10px"><?php echo $this->Fechas->actual_date($receta[0]['Consultasexterna']['fecha']); ?>
                                        </span>
                                </div>
                                </div>
                                    <span class="clear"></span>
                                </div>
                            </div>
                        <!-- end firma -->
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
    $(document).ready(function() {
        $("#btImprimir").click(function() {
            console.log('click');
            printElem({
                leaveOpen: true,
                printMode: 'popup',
                overrideElementCSS: [
                    '<?php //echo $this->webroot; ?>css/imprimir.css',
                   {href: '<?php //echo $this->webroot; ?>css/printable.css', media: 'print'}]
            });
            //printElem({ overrideElementCSS: ['http://www.imprenta.com/css/printable.css'] });
        });

        function printElem(options) {
            $('#zonaImpresion').printElement(options);
        }

    });
</script>